﻿//------------------------------------------------------------
// Author: 烟雨迷离半世殇
// Mail: 1778139321@qq.com
// Data: 2019年12月31日 16:33:28
//------------------------------------------------------------

using System;
using System.Collections.Generic;


namespace NKG_MVVM_UI
{
    public class StateManager : SingletonTemplate<StateManager>
    {
        /// <summary>
        /// 默认容量
        /// </summary>
        public const int Capacity = 30;

        public Dictionary<Type, Queue<AState>> AllStates = new Dictionary<Type, Queue<AState>>();

        public void AddState(AState aState)
        {
            if (AllStates.TryGetValue(aState.GetType(), out var queue))
            {
                while (queue.Count >= Capacity)
                {
                    queue.Dequeue();
                }

                queue.Enqueue(aState);
            }
            else
            {
                Queue<AState> tempQueue = new Queue<AState>();
                tempQueue.Enqueue(aState);
                AllStates.Add(aState.GetType(), tempQueue);
            }
        }

        public void LogTargetState<T>() where T : AState
        {
            if (AllStates.TryGetValue(typeof(T), out var queue))
            {
                int index = 0;
                foreach (var AState in queue)
                {
                    Console.WriteLine($"第{index++}个{typeof(T)}的内容为{AState}");
                }
            }
        }
    }
}